using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using CXMLStudioIDE.WinFormsUI.Docking;
using CXMLStudioIDE.Common;
using CXMLStudioIDE.WinFormsUI.CXMLStudioControls;
using CXMLStudioIDE.DataAccessLayer;
using CXMLStudioIDE.Common.EntityProperties;
using CXMLStudioIDE.BusinessLayer;

namespace CXMLStudioIDE.Forms
{
    public partial class PropertyWindowForm : ToolWindowForm
    {
        #region Declarations
        private UndoManager undoMgr = null;
        //Define a delegate for other windows to handle the event.
        public delegate void OnPropertyChanged(Object obj);

        // Define an Event based on the above Delegate
        public event OnPropertyChanged PropertyChanged;
        #endregion

        #region Constructors

        public PropertyWindowForm()
        {
            InitializeComponent();
            comboBox.SelectedIndex = 0;
            propertyGrid.SelectedObject = propertyGrid;
        }

        #endregion

        protected void OnPropertyChangedEvent(Object obj)
        {
            // Check if there are any Subscribers
            if (PropertyChanged != null)
            {
                // Call the Event
                PropertyChanged(this.propertyGrid.SelectedObject);
            }
        }

        /// <summary>
        /// This property is to get the current control for which the
        /// properties are being displayed.
        /// </summary>
        public object CurrentControl
        {
            get
            {
                return this.comboBox.Items[0];
            }
        }

        public object PropertyGridSelectedObject
        {
            set
            {
                this.propertyGrid.SelectedObject = value;
                this.comboBox.Items.Clear();
                if (value != null)
                {
                    this.comboBox.Items.Add(value);
                    this.comboBox.SelectedItem = this.comboBox.Items[0];
                }

            }
            get
            {
                return this.propertyGrid.SelectedObject;
            }
        }

        public object[] PropertyGridSelectedObjects
        {
            set
            {
                this.propertyGrid.SelectedObjects = value;
                this.comboBox.Items.Clear();
                if (value != null)
                {
                    this.comboBox.Items.Add(value);
                    this.comboBox.SelectedItem = this.comboBox.Items[0];
                }
            }
            get
            {
                return this.propertyGrid.SelectedObjects;
            }
        }

        private void propertyGrid_PropertyValueChanged(object s, PropertyValueChangedEventArgs e)
        {
            OnPropertyChangedEvent(s);
        }


    }
}